<?php


namespace app\common\lib;


class ClassArr
{
    public static function smsClassStat(){
        return [
            "ali" => "app\common\lib\sms\AliSms",
            "baidu" => "app\common\lib\sms\BaiduSms",
            "jd" => "app\common\lib\sms\JdSms",
        ];
    }
    public static function uploadClassStat(){
        return [
            "text" => "xx",
            "image" => "xxx",
        ];
    }
    public static function initClass($type, $class, $params = [], $needInstance = false){
        // 如果我们工厂模式调用的方法是静态的，那么我们这个地方返回类库AliSms
        // 如果不是静态的，我们需要返回对象
        if(!array_key_exists($type, $class)){
            return false;
        }
        $className = $class[$type];
        // new ReflectionClass('AliSms) => 建立AliSms反射类
        // newInstanceArgs($args)  => 相当于实例化AliSms对象
        return $needInstance == true ? (new \ReflectionClass($className))->newInstanceArgs($params) : $className;
    }
}
